<script>
	export default {
		data() {
			return {
				money: 0,
				userInfo: {}
			}
		},
		onLoad(){
			this.getUserInfo();
		},
		methods: {
			async getUserInfo(){
				uni.showLoading({
					title: "加载中..."
				});
				const res = await this.http("get", "/api/user/user_info");
				uni.hideLoading();
				this.userInfo = res.data;
			},
			async recharge(){
				if(this.money == 0){
					this.toast("请输入充值金额");
					return;
				}
				uni.showLoading({
					title: "提交中..."
				});
				const res = await this.http("post", "/api/index/charge", {
					money: this.money
				});
				uni.hideLoading();
				this.toast(res.message);
				
				wx.requestPayment({
					timeStamp: res.data.timeStamp,
					nonceStr: res.data.nonceStr,
					package: res.data.package,
					signType: res.data.signType,
					paySign: res.data.paySign,
					success(res) {
						uni.showToast({
							title: '支付成功',
							icon: 'none',
							duration: 2000,
							success() {
								uni.reLaunch({
									url:'/pages/index/index?tabIndex=1'
								});
							}
						})
					},fail(e) {
						console.log(e)
					}
				})
				
				
				
				if(res.code == 0){
					uni.navigateBack();
				}
			}
		}
	}
</script>
<template>
	<view class="my-content">
		<view class="recharge-top">
			<view class="recharge-text">
				<text>钱包余额</text>
				<text class="big">{{userInfo.amount}}</text>
			</view>
			<image src="../../static/my/bg3.png" mode="widthFix"></image>
		</view>
		<view class="form-item">
			<text>充值金额</text>
			<input type="text" placeholder="请输入金额" v-model="money">
		</view>
		<view class="pay" @click="recharge">
			<image src="../../static/my/wx.png" mode="widthFix"></image>
		</view>
	</view>
</template>



<style lang="less">
	.my-content{
		width: 100%;
		padding: 30upx;
		box-sizing: border-box;
		.recharge-top{
			width: 100%;
			padding: 20upx;
			box-sizing: border-box;
			position: relative;
			image{
				width: 100%;
				height: auto;
			}
			.recharge-text{
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
				display: flex;
				flex-flow: column;
				align-items: center;
				justify-content: center;
				z-index: 2;
				text{
					font-size: 46upx;
					color: #000;
					font-weight: bold;
				}
				.big{
					font-size: 90upx;
				}
			}
		}
		.form-item{
			width: 100%;
			border-radius: 16upx;
			background: #FFFFFF;
			box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.3);
			padding: 20upx;
			box-sizing: border-box;
			text{
				font-size: 36upx;
				color: #000;
				font-weight: bold;
			}
			input{
				width: 100%;
				margin-top: 10upx;
				font-size: 32upx;
			}
		}
		.pay{
			width: 100%;
			border-radius: 8px;
			background: #FFFFFF;
			box-sizing: border-box;
			border: 1px solid #26A743;
			box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.3);
			margin-top: 200upx;
			padding: 10upx;
			image{
				width: 40%;
				height: auto;
				display: block;
				margin: 0 auto;
			}
		}
	}
</style>